{% extends "tabler/dashboard_base.html" %}
{% from "helpers/_formhelpers.html" import render_field %}

{% block title %}appname Files{% endblock %}

{% block body %}
<div class="my-3 my-md-5">
    <div class="container">
        <div class="page-header">
            <h1 class="page-title">
                {{ team.name }} Files
            </h1>
        </div>
        <div class="row">
            <div class="col-12 col-md-8">
                <div class="card">
                    <div class="table-responsive">
                        <table class="table table-hover table-outline table-vcenter text-nowrap card-table">
                            <thead>
                                <tr>
                                <th class="text-center">File Name</th>
                                <th class="text-center">Description</th>
                                <th class="text-center">Created By</th>
                                <th class="text-center">Download</th>
                                <th class="text-center">Delete</th>
                                </tr>
                            </thead>
                            <tbody>
                            {% for file in files %}
                                <tr>
                                    <td class="text-truncate" style="max-width: 150px;">
                                        {{ file.file_name }}
                                    </td>
                                    <td>
                                        {{ file.description }}
                                    </td>
                                    <td>
                                        <div>{{ file.user.email }}</div>
                                        <div class="small text-muted">
                                            Created: {{ file.created }}
                                        </div>

                                    </td>
                                    <td class="text-center">
                                        <a href="{{ url_for('.download_file', team_id=team.id, file_id=file.id) }}" class="btn btn-secondary btn-sm">Download</button>

                                    </td>
                                    <td class="text-center">
                                        <form role="form" action="{{ url_for('.destroy_file', team_id=team.id, file_id=file.id) }}" method="post">
                                            {{ simple_form().hidden_tag() }}

                                            <button type="submit" class="btn btn-danger btn-sm">Remove</button>
                                        </form>

                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="col-12 col-md-4">
                <div class="card">
                    <div class="card-header">
                            <h3 class="card-title">Add New File</h3>
                    </div>
                    <form role="form" enctype="multipart/form-data" action="{{ url_for('dashboard_files.add_file', team_id=team.id) }}" method="post">
                        <div class="card-body">
                            {{ form.hidden_tag() }}
                            {{ render_field(form.attachment) }}

                            {{ render_field(form.description) }}

                        </div>
                        <div class="card-footer text-left">
                            <div class="d-flex">
                                <button type="submit" class="btn btn-primary">Add</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}